Finished Week2 JS Daryna (DARYNA_TKACHENKO-w2-JavaScript)#1
Finished Week2 JS Daryna (DARYNA_TKACHENKO-w2-JavaScript)#1dashaaaa21 wants to merge 7 commits intoHackYourAssignment:mainfrom
Conversation
dardecena
left a comment
There was a problem hiding this comment.
Nice work overall!
Ex 5 needs some improvement.
| export function giveCompliment(name) { | ||
|
|
||
| const compliments = [ | ||
| "nice", | ||
| "kind", | ||
| "smart", | ||
| "funny", | ||
| "good", | ||
| "cool", | ||
| "sweet", | ||
| "happy", | ||
| "friendly", | ||
| "great" | ||
| ]; | ||
|
|
||
| const randomCompliment = compliments[Math.floor(Math.random() * compliments.length)]; | ||
|
|
||
|
|
||
| return `You are ${randomCompliment}, ${name}!`; | ||
|
|
There was a problem hiding this comment.
Great job using ES6 template literals 👍
There was a problem hiding this comment.
Thank you! I’m enjoying working with ES6 features.
|
|
||
| const myName = 'Daria'; |
| export function calculateDogAge(age) { | ||
| return `Your doggie is ${age * 7} years old in dog years!`; |
| function selectRandomly(array) { | ||
| return array[Math.floor(Math.random() * array.length)]; |
There was a problem hiding this comment.
Good job completing the function.
A point of improvement here is the function argument name 'array', it's better to use a more descriptive name (eg. 'choice') to avoid confusion with the build-in Array object or data type.
There was a problem hiding this comment.
Thank you! I’ve updated the argument name to be more descriptive
| vine: 5.75, | ||
| water: 0.73, | ||
| juice: 1.26, | ||
| croissant: 3.98, | ||
| coffe: 2.33 |
| function calculateTotalPrice(object) { | ||
| let total = 0; | ||
| for (let item in object) { | ||
| total += object[item]; | ||
| } | ||
| return `Total: €${total.toFixed(2)}`; |
There was a problem hiding this comment.
Nice!
Additional challenge: what's another method you can use to add up all the items in the object
There was a problem hiding this comment.
Thank you! I’ve also added this approach as a comment in the code
Additional challenge: These lines go through all the keys in the object and add their values to total.
Another way is to use
function calculateTotalPrice(object) { let total = Object.values(object).reduce((sum, val) => sum + val, 0); returnTotal: €${total.toFixed(2)}; }
| function test1() { | ||
| console.log('\nTest 1: calculateTotalPrice should take one parameter'); | ||
| // TODO replace this comment with your code | ||
| console.assert(calculateTotalPrice.length === 1, "Should take one parameter"); |
| const expected = "Total: €14.05"; | ||
| const actual = calculateTotalPrice(cartForParty); | ||
| console.assert(actual === expected, `Expected "${expected}", got "${actual}"`); |
| function filterPrivateData(employees) { | ||
| return employees.map(employee => { | ||
| const { name, occupation, email } = employee; | ||
| return { name, occupation, email }; | ||
| }); | ||
| } |
There was a problem hiding this comment.
I sincerely appreciate your detailed feedback and guidance
dardecena
left a comment
There was a problem hiding this comment.
Super!!!! 🚀
Thanks for making the necessary changes, and taking time to do the extra challenge.
| function selectRandomly(choices) { | ||
| return choices[Math.floor(Math.random() * choices.length)]; |
|
|
||
| export function tellFortune(/* TODO add parameter(s) here */) { | ||
| // TODO complete this function | ||
| export function tellFortune(kids, partners, places, jobs) { |
| function addToShoppingCart(item) { | ||
| if (item !== undefined) { | ||
| shoppingCart.push(item); | ||
|
|
||
| if (shoppingCart.length > 3) { | ||
| shoppingCart.shift(); | ||
| } | ||
| } | ||
|
|
||
| return `You bought ${shoppingCart.join(', ')}!`; |
All Week 2 exercises are completed.
Tests passed for ex1–ex3.
ex4–ex7 are ready for manual review by a mentor.